import { CopyControllerBase } from "./CopyControllerBase";
import { DataEvent } from "../../../events/DataEvent";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { KeyEvent } from "../../../../../com/gengine/keyBoard/KeyEvent";
import { KeyCode } from "../../../../../com/gengine/keyBoard/KeyCode";
import { CrossDefenceCopyConfig } from "../../../resource/CrossDefenceCopyConfig";
import { CrossDefenceCopyBuildMenu } from "../crossDefenceCopy/CrossDefenceCopyBuildMenu";
import { Language } from "../../../../../extend/language/Language";
import { NetDispatcher } from "../../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../../mvc/ServerCommand";
import { KeyBoardManager } from "../../../../../com/gengine/keyBoard/KeyBoardManager";
import { CrossDefenceCopyBlessMenu } from "../crossDefenceCopy/CrossDefenceCopyBlessMenu";
import { CrossDefenceCopyTowerBuilder } from "../crossDefenceCopy/CrossDefenceCopyTowerBuilder";
import { CrossDefenceCopyInfoPanel } from "../crossDefenceCopy/CrossDefenceCopyInfoPanel";
import { CrossDefenceCopyGuider } from "../crossDefenceCopy/CrossDefenceCopyGuider";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
import { Global } from "../../../../../com/gengine/global/Global";
import { SCopyMsgInfo } from "../../../../../Message/Public/SCopyMsgInfo";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { SPlayerItem } from "../../../../../Message/Public/SPlayerItem";
import { SPublicNotice } from "../../../../../Message/Public/SPublicNotice";
import { TCrossDefenseUpgrade } from "../../../../../Message/Db/Tables/TCrossDefenseUpgrade";
import { SEntityId } from "../../../../../Message/Public/SEntityId";
import { GameMapUtil } from "../../../scene/map/GameMapUtil";
import { Game } from "../../../Game";
import { SPoint } from "../../../../../Message/Public/SPoint";
import { GameProxy } from "../../../mvc/GameProxy";
import { MonsterPlayer } from "../../../scene/player/entity/MonsterPlayer";
import { SEntityInfo } from "../../../../../Message/BroadCast/SEntityInfo";
import { EEntityType } from "../../../../../Message/Public/EEntityType";
import { BossConfig } from "../../../resource/BossConfig";
import { BossRule } from "../../../rules/BossRule";
import { ThingUtil } from "../../../scene/layer/utils/ThingUtil";
import { SceneRange } from "../../../scene/map/SceneRange";
import { EntityType } from "../../../rules/EntityType";
import { SystemSetter } from "../../system/SystemSetter";
import { TDefenseBressUpgrade } from "../../../../../Message/Db/Tables/TDefenseBressUpgrade";
import { CrossDefenceGuideBook } from "../crossDefenceCopy/CrossDefenceGuideBook";
import { CrossDefenceCopySkillMenu } from "../crossDefenceCopy/CrossDefenceCopySkillMenu";
import { CrossDefenceCopyRewardWin } from "../crossDefenceCopy/CrossDefenceCopyRewardWin";
//class CrossDefenceCopyController
    
    export  class CrossDefenceCopyController extends CopyControllerBase
    {
        constructor()
        {
            super();
            return;
        }

        /* internal  */outNpcHandler(arg1: DataEvent): void
        {
            Dispatcher.removeEventListener(EventName.AI_NpcOutDestance, this.outNpcHandler);
            if (!(this._guideBook == null) && !this._guideBook.isHide) 
            {
                this._guideBook.hide();
            }
            return;
        }

        /* internal  */keyBoardDownHandler(arg1: KeyEvent): void
        {
            if (arg1.keyData.keyCode != KeyCode.ESCAPE) 
            {
                return;
            }
            var loc1=new DataEvent("sdf");
            loc1.data = arg1.keyData.keyCode - 48;
            this.keyDownHandler(loc1);
            return;
        }

        /* internal  */stageResizeHandler(arg1: DataEvent): void
        {
            var loc1=this.getBuildMenuPoint();
            this.buildMenu.show(loc1.x, loc1.y - 60);
            var loc2=loc1.x + this.buildMenu.width + 1;
            if (cache.crossDefenceCopy.difficulty == 2) 
            {
                this.blessMenu.show((loc1.x + this.buildMenu.width - 1), loc1.y - 60);
                loc2 = this._blessMenu.x + this._blessMenu.width + 1;
            }
            if (loc2 >= 900) 
            {
                loc2 = 900;
                loc1.y = loc1.y - 80;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.SpecialSkillDelaySetSkillPanelsPlace, new Object /* flash.geom.Point */(loc2 - 10, loc1.y - 33)));
            return;
        }

        /* internal  */keyDownHandler(arg1: DataEvent): void
        {
            if (cache.crossDefenceCopy.isGuiding) 
            {
                return;
            }
            var loc1=uint(arg1.data) + 48;
            var loc2=loc1 - KeyCode.N1;
            var loc3=CrossDefenceCopyConfig.instance.getInitBuildMenuConfig();
            if (loc1 != KeyCode.ESCAPE) 
            {
                if (!(loc2 >= 0 && loc2 < loc3.length)) 
                {
                    return;
                }
            }
            else if (this._builder != null) 
            {
                this._builder.endBuildControl();
                this._builder.hideUpdateMenu();
            }
            var loc4=cache.crossDefenceCopy.getBuildableList(loc3);
            if (loc2 < 0 || loc2 >= loc4.length) 
            {
                return;
            }
            if (loc4[loc2] == false) 
            {
                return;
            }
            var loc5;
            if ((loc5 = loc3[loc2]) == null) 
            {
                return;
            }
            if (!(this._builder == null) && this._builder.isBuildingSameTower(loc5)) 
            {
                this._builder.endBuildControl();
                this._builder.hideUpdateMenu();
                return;
            }
            if (this._builder != null) 
            {
                this._builder.endBuildControl();
                this._builder.hideUpdateMenu();
            }
            this.builder.startBuildControl(loc5);
            if (cache.crossDefenceCopy.isGuiding) 
            {
                this.guider.guideStep2();
            }
            return;
        }

        /* internal  */get buildMenu(): CrossDefenceCopyBuildMenu
        {
            var loc1=null;
            if (this._buildMenu == null) 
            {
                loc1 = CrossDefenceCopyConfig.instance.getInitBuildMenuConfig();
                this._buildMenu = new CrossDefenceCopyBuildMenu(loc1, true, Language.getString(80357), Language.getString(80358));
            }
            return this._buildMenu;
        }

        protected /* override */ addListener(): void
        {
            NetDispatcher.addCmdListener(ServerCommand.CrossDefenceInfoUpdate, this.infoUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.CrossDefenceRecycleTowerSuccess, this.recycleTowerSuccessHandler);
            NetDispatcher.addCmdListener(ServerCommand.Copy_RefreshCountDownInfo, this.onCountDownInfoChange);
            NetDispatcher.addCmdListener(ServerCommand.Copy_DefendCopyAddExp, this.getExperienceUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.Copy_Fail, this.onCopyFailHandler);
            NetDispatcher.addCmdListener(ServerCommand.CrossDefenceRewardInfo, this.showRewardHandler);
            NetDispatcher.addCmdListener(ServerCommand.NoticeMsg, this.noticeHandler);
            NetDispatcher.addCmdListener(ServerCommand.CrossDefenceBlessSuccess, this.blessSuccessHandler);
            Dispatcher.addEventListener(EventName.ReqCrossDefenceCopyStartBuild, this.askStartBuildHandler);
            Dispatcher.addEventListener(EventName.ReqCrossDefenceCopyBuildTower, this.reqBuildTowerHandler);
            Dispatcher.addEventListener(EventName.CrossDefenceClickTower, this.clickTowerHandler);
            Dispatcher.addEventListener(EventName.ReqCrossDefenceCopyUpgradeTower, this.reqUpgradeTowerHandler);
            Dispatcher.addEventListener(EventName.ReqCrossDefenceCopyRecycleTower, this.reqRecycleTowerHandler);
            Dispatcher.addEventListener(EventName.CrossDefenceCloseUpdateMenu, this.closeUpdateMenuHandler);
            Dispatcher.addEventListener(EventName.Scene_AddEntity, this.entityAddToSceneHandler);
            Dispatcher.addEventListener(EventName.CrossDefenceGuideStep1Finished, this.guide1FinishedHandler);
            Dispatcher.addEventListener(EventName.CrossDefenceGuideStep2Finished, this.guide2FinishedHandler);
            Dispatcher.addEventListener(EventName.CrossDefenceGuideStep2TimerEnd, this.guideStep2EndHandler);
            Dispatcher.addEventListener(EventName.CrossDefenceBlessUpgradeReq, this.upgradeBlessHandler);
            KeyBoardManager.instance.addEventListener(KeyEvent.KEY_UP, this.keyBoardDownHandler);
            Dispatcher.addEventListener(EventName.StageResize, this.stageResizeHandler);
            return;
        }

        /* internal  */get blessMenu(): CrossDefenceCopyBlessMenu
        {
            var loc1=null;
            if (this._blessMenu == null) 
            {
                loc1 = CrossDefenceCopyConfig.instance.getInitBlessConfig();
                this._blessMenu = new CrossDefenceCopyBlessMenu(loc1, true, Language.getString(80335), Language.getString(80336));
            }
            return this._blessMenu;
        }

        /* internal  */get builder(): CrossDefenceCopyTowerBuilder
        {
            if (this._builder == null) 
            {
                this._builder = new CrossDefenceCopyTowerBuilder();
            }
            return this._builder;
        }

        /* internal  */get infoPanel(): CrossDefenceCopyInfoPanel
        {
            if (this._infoPanel == null) 
            {
                this._infoPanel = new CrossDefenceCopyInfoPanel();
            }
            return this._infoPanel;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.CrossDefenceShowGuideBook, this.showGuideBookHandler);
            return;
        }

        public /* override */ dispose(): void
        {
            return;
        }

        /* internal  */get guider(): CrossDefenceCopyGuider
        {
            if (this._guider == null) 
            {
                this._guider = new CrossDefenceCopyGuider();
            }
            return this._guider;
        }

        protected /* override */ removeListener(): void
        {
            NetDispatcher.removeCmdListener(ServerCommand.CrossDefenceInfoUpdate, this.infoUpdateHandler);
            NetDispatcher.removeCmdListener(ServerCommand.CrossDefenceRecycleTowerSuccess, this.recycleTowerSuccessHandler);
            NetDispatcher.removeCmdListener(ServerCommand.Copy_RefreshCountDownInfo, this.onCountDownInfoChange);
            NetDispatcher.removeCmdListener(ServerCommand.Copy_DefendCopyAddExp, this.getExperienceUpdateHandler);
            NetDispatcher.removeCmdListener(ServerCommand.Copy_Fail, this.onCopyFailHandler);
            NetDispatcher.removeCmdListener(ServerCommand.CrossDefenceRewardInfo, this.showRewardHandler);
            NetDispatcher.removeCmdListener(ServerCommand.NoticeMsg, this.noticeHandler);
            Dispatcher.removeEventListener(EventName.ReqCrossDefenceCopyStartBuild, this.askStartBuildHandler);
            Dispatcher.removeEventListener(EventName.ReqCrossDefenceCopyBuildTower, this.reqBuildTowerHandler);
            Dispatcher.removeEventListener(EventName.CrossDefenceClickTower, this.clickTowerHandler);
            Dispatcher.removeEventListener(EventName.ReqCrossDefenceCopyUpgradeTower, this.reqUpgradeTowerHandler);
            Dispatcher.removeEventListener(EventName.ReqCrossDefenceCopyRecycleTower, this.reqRecycleTowerHandler);
            Dispatcher.removeEventListener(EventName.CrossDefenceCloseUpdateMenu, this.closeUpdateMenuHandler);
            Dispatcher.removeEventListener(EventName.Scene_AddEntity, this.entityAddToSceneHandler);
            Dispatcher.removeEventListener(EventName.CrossDefenceGuideStep1Finished, this.guide1FinishedHandler);
            Dispatcher.removeEventListener(EventName.CrossDefenceGuideStep2Finished, this.guide2FinishedHandler);
            Dispatcher.removeEventListener(EventName.CrossDefenceGuideStep2TimerEnd, this.guideStep2EndHandler);
            KeyBoardManager.instance.removeEventListener(KeyEvent.KEY_UP, this.keyBoardDownHandler);
            Dispatcher.removeEventListener(EventName.StageResize, this.stageResizeHandler);
            return;
        }

        public /* override */ enterCopy(arg1: TCopy): void
        {
            super.enterCopy(arg1);
            Dispatcher.dispatchEvent(new DataEvent(EventName.ShowGameMainUI, false));
            Dispatcher.dispatchEvent(new DataEvent(EventName.TaskTrackShowOrHide, false));
            this.stageResizeHandler(null);
            this.showRewardHandler(null);
            this.infoPanel.show();
            this.infoPanel.updatePosition();
            var loc1=this.getBuildMenuPoint();
            if (cache.crossDefenceCopy.isGuiding) 
            {
                this.guider.guideStep1(new Object /* flash.geom.Point */(loc1.x - 14, loc1.y - 140));
            }
            return;
        }

        /* internal  */getBuildMenuPoint(): Object /* flash.geom.Point */
        {
            return new Object /* flash.geom.Point */(365, Global.stage.stageHeight - 13);
        }

        public /* override */ leaveCopy(): void
        {
            super.leaveCopy();
            if (this._buildMenu != null) 
            {
                this._buildMenu.hide();
                this._buildMenu.clean();
                this._buildMenu = null;
            }
            if (this._blessMenu != null) 
            {
                this._blessMenu.hide();
                this._blessMenu.clean();
                this._blessMenu = null;
            }
            if (this._skillMenu != null) 
            {
                this._skillMenu.hide();
                this._skillMenu.clean();
                this._skillMenu = null;
            }
            if (this._infoPanel != null) 
            {
                this._infoPanel.updateExperience(0);
                this._infoPanel.hide();
                this._infoPanel = null;
            }
            if (this._builder != null) 
            {
                this._builder.hideUpdateMenu();
                this._builder.endBuildControl();
                this._builder = null;
            }
            if (this._guider != null) 
            {
                this._guider.hideGuide();
                this._guider = null;
            }
            cache.copy.defendCopyExp = 0;
            Dispatcher.dispatchEvent(new DataEvent(EventName.ShowGameMainUI, true));
            Dispatcher.dispatchEvent(new DataEvent(EventName.TaskTrackShowOrHide, true));
            return;
        }

        /* internal  */infoUpdateHandler(arg1: Object): void
        {
            this.materialUpdateHandler(null);
            this.towerCountUpdateHandler(null);
            this.springLiveUpdateHandler(null);
            this.updateMenuBuildable();
            this.updateBlessMenu();
            if (this._builder != null) 
            {
                this._builder.reflashUpdateMenu();
            }
            this.refleshTowerLevelUpable();
            return;
        }

        /* internal  */recycleTowerSuccessHandler(arg1: Object): void
        {
            if (this._builder == null) 
            {
                return;
            }
            this.builder.hideUpdateMenu();
            return;
        }

        /* internal  */onCountDownInfoChange(arg1: SCopyMsgInfo): void
        {
            if (arg1 == null) 
            {
                return;
            }
            var loc1=Math.floor((arg1.num1 + 3) / 5);
            var loc2=false;
            var loc3=false;
            if (arg1.num1 == 1) 
            {
                this.infoPanel.updateCountDown(arg1.num2);
                return;
            }
            if (arg1.num1 == 300 && cache.crossDefenceCopy.difficulty == 1) 
            {
                loc3 = true;
            }
            else if (arg1.num1 == 400 && cache.crossDefenceCopy.difficulty == 2) 
            {
                loc3 = true;
            }
            this.infoPanel.updateBossPatchNum(loc1, loc2, loc3);
            return;
        }

        /* internal  */getExperienceUpdateHandler(arg1: Object): void
        {
            if (this._infoPanel == null) 
            {
                return;
            }
            this._infoPanel.updateExperience(cache.copy.defendCopyExp);
            return;
        }

        /* internal  */onCopyFailHandler(arg1: Object): void
        {
            if (this._builder != null) 
            {
                this._builder.endBuildControl();
                this._builder.hideUpdateMenu();
            }
            return;
        }

        /* internal  */showRewardHandler(arg1: Object): void
        {
            var loc5=null;
            var loc1=cache.crossDefenceCopy.rewards;
            if (loc1 == null) 
            {
                this.infoPanel.updateReward(new DataProvider());
                return;
            }
            var loc2=loc1.playerItem;
            var loc3=new DataProvider();
            var loc4=0;
            while (loc4 < loc2.length) 
            {
                loc5 = loc2[loc4] as SPlayerItem;
                loc3.addItem(loc5);
                ++loc4;
            }
            this.infoPanel.updateReward(loc3);
            return;
        }

        /* internal  */noticeHandler(arg1: Object): void
        {
            var loc1=arg1 as SPublicNotice;
            if (loc1 == null || !(loc1.msgKey == "DefenseBossRefreshNotice")) 
            {
                return;
            }
            return;
        }

        /* internal  */blessSuccessHandler(arg1: Object): void
        {
            return;
        }

        /* internal  */materialUpdateHandler(arg1: Object): void
        {
            this.infoPanel.updateMyMateiralNum(cache.crossDefenceCopy.myMaterial);
            return;
        }

        /* internal  */towerCountUpdateHandler(arg1: Object): void
        {
            var loc1=cache.crossDefenceCopy.getTowerTotalNumLimit(cache.crossDefenceCopy.difficulty);
            this.infoPanel.updateMyTowerNum(cache.crossDefenceCopy.getMyTowerTotalNum());
            return;
        }

        /* internal  */springLiveUpdateHandler(arg1: Object): void
        {
            this.infoPanel.updateSpringLive(cache.crossDefenceCopy.springLive);
            return;
        }

        /* internal  */updateMenuBuildable(): void
        {
            if (this._buildMenu == null) 
            {
                return;
            }
            var loc1=CrossDefenceCopyConfig.instance.getInitBuildMenuConfig();
            var loc2=cache.crossDefenceCopy.getBuildableList(loc1);
            this._buildMenu.updateBuildable(loc2);
            return;
        }

        /* internal  */updateBlessMenu(): void
        {
            if (this._blessMenu == null) 
            {
                return;
            }
            var loc1=CrossDefenceCopyConfig.instance.getInitBlessConfig();
            var loc2=cache.crossDefenceCopy.getMyCurBlessData(loc1);
            this._blessMenu.updateBlassData(loc2);
            return;
        }

        /* internal  */askStartBuildHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as TCrossDefenseUpgrade;
            if (loc1 == null) 
            {
                return;
            }
            if (!(this._builder == null) && this._builder.isBuildingSameTower(loc1)) 
            {
                this._builder.endBuildControl();
                this._builder.hideUpdateMenu();
                return;
            }
            if (this._builder == null) 
            {
                this._builder = new CrossDefenceCopyTowerBuilder();
            }
            this._builder.startBuildControl(loc1);
            return;
        }

        /* internal  */reqBuildTowerHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as TCrossDefenseUpgrade;
            if (loc1 == null) 
            {
                return;
            }
            var loc2=new SEntityId();
            loc2.type = loc1.type;
            var loc3=GameMapUtil.getTilePoint(Game.scene.mouseX, Game.scene.mouseY);
            var loc4;
            (loc4 = new SPoint()).x = loc3.x;
            loc4.y = loc3.y;
            GameProxy.crossDefenceProxy.buildTower(loc2, loc4);
            return;
        }

        /* internal  */clickTowerHandler(arg1: DataEvent): void
        {
            if (!(this._builder == null) && this._builder.isBuilding) 
            {
                return;
            }
            var loc1=arg1.data as MonsterPlayer;
            if (loc1 == null) 
            {
                return;
            }
            var loc2=CrossDefenceCopyConfig.instance.getConfigByKeys(["preBoss"], [loc1.tboss.code]);
            if (loc2 == null || loc2.length == 0) 
            {
                return;
            }
            var loc3;
            if ((loc3 = CrossDefenceCopyConfig.instance.getTowerInfoByCode(loc1.bossCode, loc1)) == null) 
            {
                return;
            }
            this.builder.showUpdateMenu(loc1, loc3, true);
            return;
        }

        /* internal  */reqUpgradeTowerHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as MonsterPlayer;
            if (loc1 == null) 
            {
                return;
            }
            GameProxy.crossDefenceProxy.upgradeTower(loc1.entityInfo.entityInfo.entityId);
            return;
        }

        /* internal  */reqRecycleTowerHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as MonsterPlayer;
            if (loc1 == null) 
            {
                return;
            }
            GameProxy.crossDefenceProxy.recycleTower(loc1.entityInfo.entityInfo.entityId);
            return;
        }

        /* internal  */closeUpdateMenuHandler(arg1: DataEvent): void
        {
            this.builder.hideUpdateMenu();
            return;
        }

        /* internal  */entityAddToSceneHandler(arg1: DataEvent): void
        {
            if (this._builder == null || this._builder.getCurMenu() == null || this._builder.getCurMenu().parent == null) 
            {
                return;
            }
            var loc1=arg1.data as SEntityInfo;
            if (loc1 == null || !(loc1.entityId.type == EEntityType._EEntityTypeBoss) || loc1.points == null) 
            {
                return;
            }
            var loc2=BossConfig.instance.getInfoByName(loc1.code);
            if (loc2 == null || !BossRule.isDefenceTower(loc2.type)) 
            {
                return;
            }
            var loc3=this._builder.getCurMenu().gridePoint;
            var loc4=loc1.points[0] as SPoint;
            if (loc3 == null || loc4 == null || !(loc3.x == loc4.x) || !(loc3.y == loc4.y)) 
            {
                return;
            }
            var loc5;
            var loc6;
            if ((loc6 = (loc5 = this._builder.getCurMenu()) ? loc5.getCurInfo() : null) == null) 
            {
                return;
            }
            var loc7;
            if ((loc7 = CrossDefenceCopyConfig.instance.getTowerInfoByCode(loc6.config.targetBoss, null, loc6.owner)) == null) 
            {
                return;
            }
            this.builder.updateUpdateMenuWhenLevelUp(loc7);
            this.refleshTowerLevelUpable();
            return;
        }

        /* internal  */refleshTowerLevelUpable(): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=false;
            var loc5=false;
            var loc6=false;
            var loc1=ThingUtil.entityUtil.getEntityByRangle(SceneRange.display, EntityType.Boss, false);
            var loc7=0;
            var loc8=loc1;
            for(loc2 of loc8) 
            {
                if (!BossRule.isDefenceTower(loc2.bossInfo.type)) 
                {
                    continue;
                }
                loc3 = CrossDefenceCopyConfig.instance.getTowerInfoByCode(loc2.bossCode, loc2);
                if (loc3 == null) 
                {
                    continue;
                }
                loc4 = Language.getString(80297) == loc3.nextEffectDesc;
                loc5 = cache.crossDefenceCopy.myMaterial >= loc3.levelUpNeed;
                loc6 = loc3.owner == cache.role.entityInfo.name;
                if (loc4 || !loc5 || !loc6) 
                {
                    loc2.showCrossTowerLevelUp(true);
                    continue;
                }
                loc2.showCrossTowerLevelUp(false);
            }
            return;
        }

        /* internal  */guide1FinishedHandler(arg1: DataEvent): void
        {
            var loc1=CrossDefenceCopyConfig.instance.getInitBuildMenuConfig();
            var loc2=loc1[0];
            if (loc2 == null) 
            {
                return;
            }
            this.builder.startGuideBuildControl(loc2);
            return;
        }

        /* internal  */guide2FinishedHandler(arg1: DataEvent): void
        {
            if (this._builder != null) 
            {
                this._builder.endGuideBuildControl();
            }
            var loc1=arg1.data as Object /* flash.geom.Point */;
            if (loc1 == null) 
            {
                return;
            }
            var loc2=CrossDefenceCopyConfig.instance.getInitBuildMenuConfig();
            var loc3;
            if ((loc3 = loc2[0]) == null) 
            {
                return;
            }
            var loc4;
            (loc4 = new SEntityId()).type = loc3.type;
            var loc5;
            (loc5 = new SPoint()).x = loc1.x;
            loc5.y = loc1.y;
            GameProxy.crossDefenceProxy.buildTower(loc4, loc5);
            return;
        }

        /* internal  */guideStep2EndHandler(arg1: DataEvent): void
        {
            if (this._builder != null) 
            {
                this._builder.endGuideBuildControl();
            }
            this._guider == null;
            SystemSetter.systemGuideSetterInfo.isCrossDefenceCopyGuided = true;
            Dispatcher.dispatchEvent(new DataEvent(EventName.SaveGuideSystemSetter));
            return;
        }

        /* internal  */upgradeBlessHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as TDefenseBressUpgrade;
            if (loc1 == null) 
            {
                return;
            }
            var loc2=cache.crossDefenceCopy.getMyBlessEffectByBlessType(loc1.type);
            var loc3=loc1.nextId;
            if (loc2 <= 0) 
            {
                loc3 = loc1.curId;
            }
            GameProxy.crossDefenceProxy.upgradeBless(loc1.type, loc3);
            return;
        }

        /* internal  */showGuideBookHandler(arg1: DataEvent): void
        {
            if (this._guideBook == null) 
            {
                this._guideBook = new CrossDefenceGuideBook();
            }
            if (!this._guideBook.isHide) 
            {
                return;
            }
            this._guideBook.data = CrossDefenceCopyConfig.instance.GuideBookURLS;
            this._guideBook.show();
            Dispatcher.addEventListener(EventName.AI_NpcOutDestance, this.outNpcHandler);
            return;
        }

        /* internal */ /* var */_buildMenu: CrossDefenceCopyBuildMenu;

        /* internal */ /* var */_blessMenu: CrossDefenceCopyBlessMenu;

        /* internal */ /* var */_skillMenu: CrossDefenceCopySkillMenu;

        /* internal */ /* var */_infoPanel: CrossDefenceCopyInfoPanel;

        /* internal */ /* var */_builder: CrossDefenceCopyTowerBuilder;

        /* internal */ /* var */_guider: CrossDefenceCopyGuider;

        /* internal */ /* var */_guideBook: CrossDefenceGuideBook;

        public /* var */isBuildingTower: Boolean=false;

        /* internal */ /* var */_winReward: CrossDefenceCopyRewardWin;
    }
